﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PPI.Client.Interface;
using PPI.Client.Logic.Inspection;
using PPI.Client.Logic.Utility;
using PPI.Entities;
using PPI.Entities.Inspections;
using PPI.Entities.Utility;

namespace PPI.Client.Presenter
{
    public class FilterTypePresenter
    {
        private IFilterType m_view;

        public FilterTypePresenter(IFilterType view)
        {
            this.m_view = view;
        }

        public void Search()
        {
            switch(m_view.VisitType)
            {
                case "GPS Structure":
                    List<EVendor_Visit_XMissionStructure> tmpListVendor = PPI.Client.Logic.LVendor_Visit_XMissionStructure.GetMobileProject(m_view.SelectedId,m_view.ConnectionString);
                    if(tmpListVendor.Count == 1)
                        m_view.SelectedVisit = tmpListVendor[0];
                    break;
                case "GPS Pole":
                    List<EVendor_Visit_XMissionStructure> tmpListVendorPole = PPI.Client.Logic.LVendor_Visit_XMissionStructure.GetMobileProjectByPole(m_view.SelectedId, m_view.ConnectionString);
                    if (tmpListVendorPole.Count == 1)
                        m_view.SelectedVisit = tmpListVendorPole[0];
                    break;
                case "Inspection Structure":
                    List<EInspectionStructure> tmpListStructures =LInspectionStructure.LoadProjectStructures(m_view.SelectedId, m_view.ConnectionString);
                    if(tmpListStructures.Count == 1)
                        m_view.SelectedVisit = tmpListStructures[0];
                    break;
                case "Inspection Pole":
                    List<EInspectionStructure> tmpListStructuresByPole = LInspectionStructure.LoadProjectStructuresByPole(m_view.SelectedId, m_view.ConnectionString);
                    if (tmpListStructuresByPole.Count == 1)
                        m_view.SelectedVisit = tmpListStructuresByPole[0];
                    break;
                    break;
                case "Asset":
                    List<EUtility_Asset_XMissionStructure> tmpListAssets = LUtility_Asset_XMissionStructure.SelectAllWithInspectionGps(m_view.SelectedId,m_view.ConnectionString);
                    if (tmpListAssets.Count == 1)
                        m_view.SelectedVisit = tmpListAssets[0];
                    break;
            }
        }
    }
}
